/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.apt.hanhhanh.matrimony.methods;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apt.matrimony.db.MyConnection;

/**
 *
 * @author HANHXINH
 */
public class validateAccount {
    public static boolean checkUsername(String username, String email){
        boolean flag = true;
        Connection cnn = null;
        PreparedStatement pst = null;
        ResultSet rs = null;
       
        String sqlGetAcc = "SELECT * FROM Accounts  WHERE User_Name = '" + username+"' and User_Email = '"+email+"'";
        
        
        try {
            cnn = MyConnection.connType4();
            pst = cnn.prepareCall(sqlGetAcc);
           rs = pst.executeQuery();
           if(rs.next()){
               flag=false;
               System.out.println("Username hoac Email đã tồn tại!");
           }else{
               flag = true;
               System.out.println("Username Ok!");
           }
            
        } catch (SQLException ex) {
            Logger.getLogger(Updates.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        return flag;
    }
    
    
    public static boolean checkPass(String username, String pass){
        boolean flag = false;
        Connection cnn = null;
        PreparedStatement pst = null;
        ResultSet rs = null;
       
        String sqlGetAcc = "SELECT * FROM Accounts  WHERE User_Name = '" + username;
        
        
        try {
            cnn = MyConnection.connType4();
            pst = cnn.prepareCall(sqlGetAcc);
           rs = pst.executeQuery();
           while(rs.next()){
               if(pass.equalsIgnoreCase(rs.getString("User_Password"))){
                   flag = true;
               }else{
                   flag =false;
               }
           }
            
        } catch (SQLException ex) {
            Logger.getLogger(Updates.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        return flag;
    }
}
